package tmt.usercenter.web.configure;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.auditing.DateTimeProvider;
import org.springframework.data.domain.AuditorAware;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import tmt.usercenter.web.configure.bean.AuditingDateTimeProvider;
import tmt.usercenter.web.configure.bean.CurrentDateTimeBean;
import tmt.usercenter.web.configure.bean.DateTimeService;
import tmt.usercenter.web.configure.bean.UserAuditorAware;
import tmt.usercenter.web.domain.TmtUser;

/**
 * Created by ThreeManTeam on 2017/6/14.
 */

@Configuration
@EnableJpaAuditing(auditorAwareRef = "auditorProvider", dateTimeProviderRef = "dateTimeProvider")
public class PersistenceContext {

	@Bean
	DateTimeService dateTimeService() {
		return new CurrentDateTimeBean();
	}

	@Bean
	DateTimeProvider dateTimeProvider(@Qualifier("dateTimeService") DateTimeService dateTimeService) {
		return new AuditingDateTimeProvider(dateTimeService);
	}

	@Bean
    public AuditorAware<TmtUser> auditorProvider() {
    	return new UserAuditorAware();
    }
}
